package com.tanhua.app.controller;

import com.aliyuncs.exceptions.ClientException;
import com.tanhua.app.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping(value = "/messages")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    @PostMapping(value = "/contacts",name = "添加好友")
    public ResponseEntity contacts(@RequestBody Map<String,Long> map) throws ClientException {
        System.out.println("添加好友...");
        Long userId = map.get("userId");
        return messagesService.contacts(userId);
    }

    @GetMapping(value = "/contacts",name = "查看登录人的好友列表")
    public ResponseEntity findContacts(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pagesize,String keyword) throws ClientException {

        return messagesService.findContacts(page,pagesize,keyword);
    }

    @GetMapping(value = "/likes",name = "登录人发布的动态谁点过赞")
    public ResponseEntity findLikes(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pagesize) throws ClientException {
        return messagesService.findComment(page,pagesize,1L);
    }

    @GetMapping(value = "/comments",name = "登录人发布的动态谁评论过")
    public ResponseEntity findComments(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pagesize) throws ClientException {
        return messagesService.findComment(page,pagesize,2L);
    }

    @GetMapping(value = "/loves",name = "登录人发布的动态谁喜欢过")
    public ResponseEntity findLoves(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pagesize) throws ClientException {
        return messagesService.findComment(page,pagesize,3L);
    }
}
